home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / gag / MunchingSq.lha / MunchingSq / ms2.c < prev    next >
C/C++ Source or Header  |  1987-07-07  |  2KB  |  106 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * ms2.c:    Munching Squares for the Amiga, now actually interesting.
  4.  *
  5.  * Leo L. Schwab            8706.4
  6.  * With a respectful bow and flurry of my cape to Bill Gosper.
  7.  * (I wonder if Gosper has an Amiga?)
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12.  
  13. extern void    *OpenLibrary(), *OpenScreen(), *OpenWindow(), *GetMsg();
  14.  
  15. struct NewScreen scrdef = {
  16.     0, 0, 256, 256, 1,
  17.     0, 1,
  18.     LACE,
  19.     CUSTOMSCREEN,
  20.     NULL, NULL, NULL, NULL
  21. };
  22.  
  23. struct NewWindow windef = {
  24.     0, 0, 256, 256,
  25.     -1, -1,
  26.     CLOSEWINDOW,
  27.     WINDOWCLOSE,
  28.     NULL, NULL, NULL,
  29.     NULL,        /*  Filled in later  */
  30.     NULL,
  31.     0, 0, 0, 0,
  32.     CUSTOMSCREEN
  33. };
  34.  
  35. struct Screen    *scr;
  36. struct Window    *win;
  37. void        *IntuitionBase, *GfxBase;
  38.  
  39. main (ac, av)
  40. int ac;
  41. char **av;
  42. {
  43.     register struct RastPort *rp;
  44.     register unsigned int acc, x, y, seed;
  45.     void *msg;
  46.  
  47.     openstuff ();
  48.     rp = &scr -> RastPort;
  49.     SetRast (rp, 0L);
  50.     SetDrMd (rp, COMPLEMENT);
  51.  
  52.     if (++av, --ac)
  53.         seed = atoi (*av);
  54.     else
  55.         seed = 1;
  56.  
  57.     acc = 0;
  58.     while (1) {
  59.         if (msg = GetMsg (win -> UserPort)) {    /*  Close gadget  */
  60.             ReplyMsg (msg);
  61.             break;
  62.         }
  63.  
  64. /*        Move (rp, 0L, (long) (0 ^ t));    */
  65.         acc += seed;
  66.         x = acc & 0xff;
  67.         y = ((acc & 0xff00) >> 8) ^ x;
  68.  
  69.         WritePixel (rp, (long) x , (long) y);
  70.     }
  71.  
  72.     closestuff ();
  73. }
  74.  
  75. openstuff ()
  76. {
  77.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L)))
  78.         die ("-=RJ=- is on vacation.");
  79.  
  80.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  81.         die ("Dale?  Are you there?");
  82.  
  83.     if (!(scr = OpenScreen (&scrdef)))
  84.         die ("Screens aren't happening.");
  85.  
  86.     windef.Screen = scr;
  87.     if (!(win = OpenWindow (&windef)))
  88.         die ("Window painted shut.");
  89. }
  90.  
  91. closestuff ()
  92. {
  93.     if (win)        CloseWindow (win);
  94.     if (scr)        CloseScreen (scr);
  95.     if (GfxBase)        CloseLibrary (GfxBase);
  96.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  97. }
  98.  
  99. die (str)
  100. char *str;
  101. {
  102.     puts (str);
  103.     closestuff ();
  104.     exit (20);
  105. }
  106.